<template>
  <el-form ref="searchForm" :model="searchForm" label-width="120px">
    <el-row v-if="conditionCount > 0">
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="店铺标题" prop="shopTitle" label-for="shopTitle">
          <el-input
            v-model="searchForm.shopTitle"
            element-id="shopTitle"
            placeholder="请输入店铺标题"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="商品标题" prop="goodsTitle" label-for="goodsTitle">
          <el-input
            v-model="searchForm.goodsTitle"
            element-id="goodsTitle"
            placeholder="请输入商品标题"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="售卖标题" prop="skuTitle" label-for="skuTitle">
          <el-input
            v-model="searchForm.skuTitle"
            element-id="skuTitle"
            placeholder="请输入售卖标题"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-button
          type="primary"
          style="margin-left: 10px;"
          :loading="loading.search"
          @click="handleSubmit"
        >搜索</el-button>
        <el-button @click="handleReset">重置</el-button>
        <a v-if="conditionCount > 3" style="margin-left: 10px;" @click="collapse = !collapse">
          <el-button type="text" v-if="!collapse">
            展开
            <svg-icon icon-class="ios-arrow-down" />
          </el-button>
          <el-button v-else type="text">
            收起
            <svg-icon icon-class="ios-arrow-up" />
          </el-button>
        </a>
      </el-col>
    </el-row>
    <el-row v-if="collapse">
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="开始时间">
          <el-row>
            <el-col :span="11">
              <el-form-item prop="beginTimeMin">
                <el-date-picker
                  type="datetime"
                  v-model="searchForm.beginTimeMin"
                  placeholder="请输入开始开始时间"
                  format="yyyy-MM-dd HH:mm:ss"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  style="width: 100%;"
                  clearable
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="2" style="text-align: center">-</el-col>
            <el-col :span="11">
              <el-form-item prop="beginTimeMax">
                <el-date-picker
                  type="datetime"
                  v-model="searchForm.beginTimeMax"
                  placeholder="请输入结束开始时间"
                  format="yyyy-MM-dd HH:mm:ss"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  style="width: 100%;"
                  clearable
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="结束时间">
          <el-row>
            <el-col :span="11">
              <el-form-item prop="endTimeMin">
                <el-date-picker
                  type="datetime"
                  v-model="searchForm.endTimeMin"
                  placeholder="请输入开始结束时间"
                  format="yyyy-MM-dd HH:mm:ss"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  style="width: 100%;"
                  clearable
                ></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="2" style="text-align: center">-</el-col>
            <el-col :span="11">
              <el-form-item prop="endTimeMax">
                <el-date-picker
                  type="datetime"
                  v-model="searchForm.endTimeMax"
                  placeholder="请输入结束结束时间"
                  format="yyyy-MM-dd HH:mm:ss"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  style="width: 100%;"
                  clearable
                ></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import * as utils from '@/utils/utils'
import * as ResponseStatus from '@/utils/response-status'
export default {
  name: 'GoodsAgentSearchQuick',
  data() {
    return {
      loading: {
        search: false,
      },
      conditionCount: 5,
      collapse: false,
      searchForm: {
        pageNo: 1,
        pageSize: 10,
        sortColumn: undefined,
        sortOrder: undefined,
        id: undefined,
        idMin: undefined,
        idMax: undefined,
        shopId: undefined,
        shopIdMin: undefined,
        shopIdMax: undefined,
        shopTitle: undefined,
        shopIsActive: undefined,
        shopIsActiveMin: undefined,
        shopIsActiveMax: undefined,
        goodsId: undefined,
        goodsIdMin: undefined,
        goodsIdMax: undefined,
        goodsTitle: undefined,
        goodsIsActive: undefined,
        goodsIsActiveMin: undefined,
        goodsIsActiveMax: undefined,
        goodsSkuId: undefined,
        goodsSkuIdMin: undefined,
        goodsSkuIdMax: undefined,
        skuPicUrl: undefined,
        skuTitle: undefined,
        skuSalePrice: undefined,
        skuSalePriceMin: undefined,
        skuSalePriceMax: undefined,
        skuIsActive: undefined,
        skuIsActiveMin: undefined,
        skuIsActiveMax: undefined,
        beginTime: undefined,
        beginTimeMin: undefined,
        beginTimeMax: undefined,
        endTime: undefined,
        endTimeMin: undefined,
        endTimeMax: undefined,
        version: undefined,
        versionMin: undefined,
        versionMax: undefined,
        createTime: undefined,
        createTimeMin: undefined,
        createTimeMax: undefined,
        updateTime: undefined,
        updateTimeMin: undefined,
        updateTimeMax: undefined,
        isActive: undefined,
        isActiveMin: undefined,
        isActiveMax: undefined,
      },
      dataDictCodes: ['YES_NO'],
      selects: {
        shopIsActiveSelect: [],
        goodsIsActiveSelect: [],
        skuIsActiveSelect: [],
        isActiveSelect: [],
      },
    }
  },
  computed: {},
  mounted() {
    this.initDataDict()
  },
  methods: {
    initDataDict() {
      utils
        .getDataDict(this.dataDictCodes)
        .then((response) => {
          if (response) {
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'shopIsActive',
              dataProp: 'shopIsActiveSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'goodsIsActive',
              dataProp: 'goodsIsActiveSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'skuIsActive',
              dataProp: 'skuIsActiveSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'isActive',
              dataProp: 'isActiveSelect',
            })
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    resetForm(excludeProps) {
      for (let key in this.searchForm) {
        if (excludeProps && excludeProps.includes(key)) {
          continue
        }
        this.searchForm[key] = undefined
      }
    },
    handleSubmit() {
      this.$emit('quickSearch')
    },
    handleReset() {
      this.$emit('researchTable')
    },
  },
}
</script>
<style>
.ivu-quick-opt {
  text-align: right;
}
</style>